package vistas;
import java.awt.BorderLayout;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ListadoDisponibles extends javax.swing.JFrame {
	private JPanel pnlCriterio;
	private ButtonGroup criterio;
	private JScrollPane spListado;
	private JTable tblListado;
	private JButton btnMostrar;
	private JButton btnLimpiar;
	private JRadioButton rbtnNoVenc;
	private JRadioButton rbtnVencidos;
	private JLabel lblMostrar;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				ListadoDisponibles inst = new ListadoDisponibles();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public ListadoDisponibles() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				pnlCriterio = new JPanel();
				getContentPane().add(pnlCriterio, "Center");
				pnlCriterio.setBounds(10, 16, 510, 104);
				pnlCriterio.setLayout(null);
				pnlCriterio.setBorder(BorderFactory.createTitledBorder(new LineBorder(new java.awt.Color(115,115,115), 1, true), "Criterio de busqueda", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION));
				{
					lblMostrar = new JLabel();
					pnlCriterio.add(lblMostrar);
					lblMostrar.setText("Mostrar solamente");
					lblMostrar.setBounds(28, 27, 97, 14);
				}
				{
					rbtnVencidos = new JRadioButton();
					pnlCriterio.add(rbtnVencidos);
					rbtnVencidos.setText("Vencidos");
					rbtnVencidos.setBounds(135, 23, 108, 23);
					getCriterio().add(rbtnVencidos);
				}
				{
					rbtnNoVenc = new JRadioButton();
					pnlCriterio.add(rbtnNoVenc);
					rbtnNoVenc.setText("No vencidos");
					rbtnNoVenc.setBounds(245, 23, 130, 23);
					getCriterio().add(rbtnNoVenc);
				}
				{
					btnMostrar = new JButton();
					pnlCriterio.add(btnMostrar);
					btnMostrar.setText("Mostrar listado");
					btnMostrar.setBounds(109, 58, 111, 23);
				}
				{
					btnLimpiar = new JButton();
					pnlCriterio.add(btnLimpiar);
					btnLimpiar.setText("Limpiar");
					btnLimpiar.setBounds(275, 58, 92, 23);
				}
			}
			{
				spListado = new JScrollPane();
				getContentPane().add(spListado);
				spListado.setBounds(15, 144, 499, 181);
				{
					TableModel tblListadoModel = 
							new DefaultTableModel(
											new String[] { "Codigo", "Nombre Marca", "Nombre Generico", "Fecha Vencimiento", "Cantidad",0 });
					tblListado = new JTable();
					spListado.setViewportView(tblListado);
					tblListado.setModel(tblListadoModel);
				}
			}
			pack();
			this.setSize(546, 464);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	private ButtonGroup getCriterio() {
		if(criterio == null) {
			criterio = new ButtonGroup();
		}
		return criterio;
	}

	/** Permite asignar una fila a la tabla*/
	public void agregarFila(Vector<String> datos)
	{
		DefaultTableModel dtm = (DefaultTableModel) tblListado.getModel();
		dtm.addRow(datos);
	}
	
	
	/** Permite limpiar la informacion mostrada por la tabla */
	public void limpiarFormulario(){
		TableModel tblListadoModel = 
				new DefaultTableModel(
						new String[] { "Codigo", "Nombre marca","Nombre generico",
								"Fecha Vencimiento", "Cantidad" },0);
		tblListado.setModel(tblListadoModel);
		criterio.clearSelection();
	}	
	
	public int mostraVenc ()
	{
		if (rbtnVencidos.isSelected())
			return 1;
		else return 2;
	}
}
